package base

import "fmt"

//基数
var base []byte = []byte{
	////小写字母 ： abcdghijkmnpqstuvxyz
	//97, 98, 99, 100, 103, 104, 105, 106, 107, 109, 110, 112, 113, 115, 116, 117, 118, 120, 121, 122,
	////大写字母： ABCDEFGHIJKLMNOPQRSTUVWXYZ
	//65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
	////数字：0123456789
	//48, 49, 50, 51, 52, 53, 54, 55, 56, 57,

	//随机打乱。无可猜测
	97, 104, 105, 78, 79, 80, 113, 115, 103, 67, 68,
	65, 66, 98, 99, 100, 84, 85, 86, 116,
	70, 71, 109, 110, 69, 122, 87, 88,
	112, 75, 76, 77, 117, 118, 53,
	54, 55, 56, 120, 121, 81, 82, 83, 89, 90,
	48, 49, 50, 72, 73, 74, 106, 107, 51, 52, 57,
}
//级别
var level []byte = []byte{
	// wolfer
	119, 111, 108, 102, 101, 114,
}

//基数
var baseN = len(base)
var n = int64(baseN * len(level))

func Encode(data int64) string {
	var baseNums []int
	if data > 0 {
		for data > 0 {
			m := data % n
			data = data / n
			baseNums = append([]int{int(m)}, baseNums...)
		}
	} else {
		baseNums = append(baseNums, 0);
	}
	bases := []byte{}
	//fmt.Println("===============")
	for _, num := range baseNums {
		bases = append(bases, getBaseByte(num)...)
	}
	//fmt.Println(baseNums)
	//fmt.Println(bases)
	//fmt.Println(string(bases))
	return string(bases)
}

func Decode(data string) int64 {

	bases := []byte(data)

	fmt.Println(bases)
	return 0
}

func getBaseByte(num int) []byte {

	bases := []byte{}
	l := num / baseN
	if l > 0 {
		bases = append(bases, level[l-1])
		bases = append(bases, base[num%baseN])
	} else {
		bases = append(bases, base[num])
	}
	return bases
}
